package com.bite.system.controller.sysuser;

import com.bite.common.core.contants.HttpConstants;
import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.vo.LoginUserVO;
import com.bite.system.domain.sysuser.dto.LoginDTO;
import com.bite.system.domain.sysuser.dto.SysUserSaveDIO;
import com.bite.system.domain.sysuser.vo.SysUserVO;
import com.bite.system.service.sysuser.ISystemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/sysUser")
@RestController
@Tag(name = "管理员接口")
public class SysUserController extends BaseController {


    @Autowired
    private ISystemService isystemService;
    //返回值要包含两个信息:成功/失败.失败原因 boolean int(0,1) / String msg 两个字段,定义对象
    //请求方法??,url?? sysUser/login
    //接口文档


    /**
     * 登录
     * @param loginDTO
     * @return
     */
    //接口地址/sysUser/login
    //请求方法PostMapping,登录要考虑安全性
    //请求参数-Body
    //Swagger 生成接口文档

    @PostMapping("/login")
    @Operation(summary = "管理员登录",description = "根据账号密码进行管理员登录")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3102",description = "⽤⼾不存在")
    @ApiResponse(responseCode = "3103",description = "⽤⼾名或密码错误")
    public R<String> login(@RequestBody LoginDTO loginDTO){
        return isystemService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }
    //接口自测  失败-用户存在-账号或密码错误 用户不存在  成功



    //system/sysUser/logout
    //
    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toR(isystemService.logout(token));

    }


    /**
     * 新增
     * @param sysUserSaveDIO
     * @return
     */
    //管理员的增删改查
    //接口地址:sysUser/add
    //请求方法:post
    //请求参数
    @Operation(summary = "新增管理员",description = "根据提供的信息新增管理员")
    @ApiResponse(responseCode = "1000",description = "操作成功")
    @ApiResponse(responseCode = "2000",description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3101",description = "⽤⼾已存在")
    @PostMapping("/add")
    public R<Void> add(@RequestBody SysUserSaveDIO sysUserSaveDIO){
        return toR(isystemService.add(sysUserSaveDIO));
    }


    /**
     * 删除
     * @param userId
     * @return
     */
    @DeleteMapping("/{userId}")
    @Operation(summary = "删除⽤⼾", description = "通过⽤⼾id删除⽤⼾")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.PATH, description = "⽤⼾ID")})
            @ApiResponse(responseCode = "1000", description = "成功删除⽤⼾")
            @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
            @ApiResponse(responseCode = "3101", description = "⽤⼾不存在")
    public R<Void> delete(@PathVariable Long userId) {
        return null;
    }


    /**
     * 查看详情
     * @param userId
     * @param sex
     * @return
     */
    @Operation(summary = "⽤⼾详情", description = "根据查询条件查询⽤⼾详情")
    @GetMapping("/detail")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "⽤⼾ID"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "⽤⼾性别")
    })
            @ApiResponse(responseCode = "1000", description = "成功获取⽤⼾信息")
            @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
            @ApiResponse(responseCode = "3101", description = "⽤⼾不存在")
    public R<SysUserVO> detail(Long userId, @RequestParam(required = false) String sex) {
        return null;
    }



    //接口地址 /system/sysUser/info
    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return isystemService.info(token);
    }



}
